package com.autosalon.DAO;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

public class InvokedEntity extends MainDAO{
	
	private final Class entity;
	
	public InvokedEntity(Class entity){
		this.entity = entity;
	}
	
	public Object getById(Long id){
		return getSession().load(entity, id);
	}
	
	public Object getOneByParam(String param, Object value){
		return getSession().createCriteria(entity).add(Restrictions.like(param, value)).list().get(0);
	}
	
	public List<Object> getListByParam(String param, Object value){
		return getSession().createCriteria(entity).add(Restrictions.like(param, value)).list();
	}

	public List<Object> getAll(int from, int to){
		getSession().beginTransaction();
		Criteria criteria = getSession().createCriteria(entity);
		criteria.setFirstResult(from);
		criteria.setMaxResults(to-from);
		return criteria.list();
	}
	
	

}
